import { LocalStorageKeys } from '@/enums/localstorage'
import { getItem, setItem, removeItem } from '@/utils'
import { defineStore } from 'pinia'
import {login} from '~/api/login'
interface LoginRequestData {
  username: string
  password: string,
  code:string,
  uuid:string
}

export const useUserStore = defineStore('user', () => {
  /** 登录操作 */
  const Login = async (data:LoginRequestData) => {
    return new Promise((resolve, reject) => {
      login(data).then(res => {
        if(res.code == 200){
          setItem('token',res.token)
          resolve()
        }
        else{
          reject(res.msg)
        }
      }).catch(err => {
        reject(err)
      })
    })
  }
  /** 退出登录操作 */
  const logout = async () => {
    removeItem()
  }
  return { Login, logout }
})
